package com.lagou.h2.provider.service.impl;

import com.lagou.service.api.MethodService;
import org.apache.dubbo.config.annotation.Service;

import java.util.concurrent.ThreadLocalRandom;

@Service
public class MethodServiceImpl implements MethodService {

    @Override
    public String methodA() {
        sleep();
        return "this is methodA";
    }

    @Override
    public String methodB() {
        sleep();
        return "this is methodB";
    }

    @Override
    public String methodC() {
        sleep();
        return "this is methodC";
    }

    public void sleep() {
        try {
            Thread.sleep(getRandomInt(300));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public int getRandomInt(int random) {
        return ThreadLocalRandom.current().nextInt(random);
    }
}
